package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ActivityCycle;
import com.ruoyi.system.service.IActivityCycleService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 活动信息管理Controller
 * 
 * @author 海田精品馆
 * @date 2022-07-27
 */
@Controller
@RequestMapping("/system/activityCycle")
public class ActivityCycleController extends BaseController
{
    private String prefix = "system/activityCycle";

    @Autowired
    private IActivityCycleService activityCycleService;

    @RequiresPermissions("system:activityCycle:view")
    @GetMapping()
    public String activityCycle()
    {
        return prefix + "/activityCycle";
    }

    /**
     * 查询活动信息管理列表
     */
    @RequiresPermissions("system:activityCycle:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ActivityCycle activityCycle)
    {
        startPage();
        List<ActivityCycle> list = activityCycleService.selectActivityCycleList(activityCycle);
        return getDataTable(list);
    }

    /**
     * 导出活动信息管理列表
     */
    @RequiresPermissions("system:activityCycle:export")
    @Log(title = "活动信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ActivityCycle activityCycle)
    {
        List<ActivityCycle> list = activityCycleService.selectActivityCycleList(activityCycle);
        ExcelUtil<ActivityCycle> util = new ExcelUtil<ActivityCycle>(ActivityCycle.class);
        return util.exportExcel(list, "活动信息管理数据");
    }

    /**
     * 新增活动信息管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存活动信息管理
     */
    @RequiresPermissions("system:activityCycle:add")
    @Log(title = "活动信息管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ActivityCycle activityCycle)
    {
        return toAjax(activityCycleService.insertActivityCycle(activityCycle));
    }

    /**
     * 修改活动信息管理
     */
    @RequiresPermissions("system:activityCycle:edit")
    @GetMapping("/edit/{actId}")
    public String edit(@PathVariable("actId") Long actId, ModelMap mmap)
    {
        ActivityCycle activityCycle = activityCycleService.selectActivityCycleByActId(actId);
        mmap.put("activityCycle", activityCycle);
        return prefix + "/edit";
    }

    /**
     * 修改保存活动信息管理
     */
    @RequiresPermissions("system:activityCycle:edit")
    @Log(title = "活动信息管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ActivityCycle activityCycle)
    {
        return toAjax(activityCycleService.updateActivityCycle(activityCycle));
    }

    /**
     * 删除活动信息管理
     */
    @RequiresPermissions("system:activityCycle:remove")
    @Log(title = "活动信息管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(activityCycleService.deleteActivityCycleByActIds(ids));
    }
}
